﻿Imports DataSet_apaTableAdapters
Imports System.Data.SqlClient
Partial Class Configura_Pantallas
    Inherits System.Web.UI.Page
    Dim sdsReporteCampos As New SqlDataSource
    Dim pantallas As New pantallasTableAdapter
    Dim sSQL As String
    Protected Sub BtnNuevo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnNuevo.Click
        TxBPantalla.Enabled = True
        TxBDescripcion.Enabled = True
        TxBPantalla.Text = ""
        TxBDescripcion.Text = ""
        TxBPantalla.Focus()
        BtnNuevo.Enabled = False
        BtnBorra.Enabled = False
        BtnSalvar.Enabled = True
    End Sub

    Protected Sub BtnSalvar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSalvar.Click

        Dim pantalla As String = TxBPantalla.Text
        Dim Descripcion As String = TxBDescripcion.Text
        If Len(pantalla) > 0 Or Len(Descripcion) > 0 Then


            sSQL = "INSERT INTO Pantallas(pantalla, descripcion) VALUES  ('" + pantalla + "'" & "," & "'" + Descripcion + "')"
            Try
                sdsReporteCampos.ConnectionString = ConfigurationManager.ConnectionStrings("GanaderiaConnectionString").ConnectionString
                sdsReporteCampos.InsertCommand = sSQL
                sdsReporteCampos.Insert()
            Catch ex As Exception

            End Try
        End If

        TxBPantalla.Enabled = False
        TxBDescripcion.Enabled = False
        TxBPantalla.Text = ""
        TxBDescripcion.Text = ""
        ActualizaGrid()
        BtnNuevo.Enabled = True
        BtnBorra.Enabled = False
        BtnSalvar.Enabled = False

    End Sub

    Protected Sub Configura_Pantallas_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ActualizaGrid()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub GVPantalla_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GVPantalla.SelectedIndexChanged
        Dim clavePantalla As String = GVPantalla.SelectedRow.Cells(1).Text
        Dim descPantalla As String = GVPantalla.SelectedRow.Cells(2).Text
        TxBPantalla.Text = clavePantalla
        TxBDescripcion.Text = descPantalla
        BtnBorra.Enabled = True
        BtnNuevo.Enabled = False
        BtnSalvar.Enabled = False
    End Sub

    Protected Sub BtnBorra_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnBorra.Click
        Dim registro As String = TxBPantalla.Text
        sSQL = "DELETE FROM Pantallas where pantalla = " & "'" + registro + "'"
        Try

            sdsReporteCampos.ConnectionString = ConfigurationManager.ConnectionStrings("GanaderiaConnectionString").ConnectionString
            sdsReporteCampos.DeleteCommand = sSQL
            sdsReporteCampos.Delete()

        Catch ex As Exception

        End Try
        TxBPantalla.Text = ""
        TxBDescripcion.Text = ""
        BtnNuevo.Enabled = True
        BtnBorra.Enabled = False
        BtnSalvar.Enabled = False
        ActualizaGrid()
    End Sub
    Sub ActualizaGrid()
        GVPantalla.DataSource = pantallas.GetPantallas
        GVPantalla.DataBind()
    End Sub
End Class
